package main;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

import model.dao.CommonsDao;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import utils.Constants;
import view.VentanaPrincipal;

public class Main {
	private static Logger logger;

	public static void main(String args[]) {
		URL url;
		try {
			url = new File(Constants.DATA_FOLDER + "/log4j.properties").toURI().toURL();
			PropertyConfigurator.configure(url);
			logger = Logger.getLogger(Main.class);
		} catch (MalformedURLException e1) {
			logger.error(e1);
		}
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			CommonsDao commonsDao = new CommonsDao();
			commonsDao.exectuteScript(Constants.DATA_FOLDER + "/scripts/create-base.sql", ";");
			new VentanaPrincipal();
		} catch (Throwable e) {
			JOptionPane.showMessageDialog(null, e);
			logger.error(e);
			System.exit(0);
		}
	}

}
